// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.characterTextures;

import zombie.core.textures.SmartTexture;
import zombie.core.textures.TextureCombinerCommand;
import zombie.core.textures.TextureCombinerShaderParam;
import zombie.util.StringUtils;

public final class ItemSmartTexture extends SmartTexture {
    public static final int DecalOverlayCategory = 300;
    private String m_texName = null;

    public ItemSmartTexture(String tex) {
        if (tex != null) {
            this.add(tex);
            this.m_texName = tex;
        }
    }

    public ItemSmartTexture(String tex, float hue) {
        this.addHue("media/textures/" + tex + ".png", 300, hue);
        this.m_texName = tex;
    }

    public void setDenimPatches(BloodBodyPartType bodyPart) {
        if (!StringUtils.isNullOrEmpty(CharacterSmartTexture.DenimPatchesMaskFiles[bodyPart.index()])) {
            String string = "media/textures/patches/" + CharacterSmartTexture.DenimPatchesMaskFiles[bodyPart.index()] + ".png";
            int _int = CharacterSmartTexture.DecalOverlayCategory + bodyPart.index();
            this.addOverlayPatches(string, "media/textures/patches/patchesmask.png", _int);
        }
    }

    public void setLeatherPatches(BloodBodyPartType bodyPart) {
        if (!StringUtils.isNullOrEmpty(CharacterSmartTexture.LeatherPatchesMaskFiles[bodyPart.index()])) {
            String string = "media/textures/patches/" + CharacterSmartTexture.LeatherPatchesMaskFiles[bodyPart.index()] + ".png";
            int _int = CharacterSmartTexture.DecalOverlayCategory + bodyPart.index();
            this.addOverlayPatches(string, "media/textures/patches/patchesmask.png", _int);
        }
    }

    public void setBasicPatches(BloodBodyPartType bodyPart) {
        if (!StringUtils.isNullOrEmpty(CharacterSmartTexture.BasicPatchesMaskFiles[bodyPart.index()])) {
            String string = "media/textures/patches/" + CharacterSmartTexture.BasicPatchesMaskFiles[bodyPart.index()] + ".png";
            int _int = CharacterSmartTexture.DecalOverlayCategory + bodyPart.index();
            this.addOverlayPatches(string, "media/textures/patches/patchesmask.png", _int);
        }
    }

    public void setBlood(String tex, BloodBodyPartType bodyPart, float intensity) {
        String string = "media/textures/BloodTextures/" + CharacterSmartTexture.MaskFiles[bodyPart.index()] + ".png";
        int _int = CharacterSmartTexture.DecalOverlayCategory + bodyPart.index();
        this.setBlood(tex, string, intensity, _int);
    }

    public void setBlood(String tex, String mask, float intensity, int category) {
        intensity = Math.max(0.0F, Math.min(1.0F, intensity));
        TextureCombinerCommand textureCombinerCommand = this.getFirstFromCategory(category);
        if (textureCombinerCommand != null) {
            for (int _int = 0; _int < textureCombinerCommand.shaderParams.size(); _int++) {
                TextureCombinerShaderParam textureCombinerShaderParam = (TextureCombinerShaderParam)textureCombinerCommand.shaderParams.get(_int);
                if (textureCombinerShaderParam.name.equals("intensity")
                    && (textureCombinerShaderParam.min != intensity || textureCombinerShaderParam.max != intensity)) {
                    textureCombinerShaderParam.min = textureCombinerShaderParam.max = intensity;
                    this.setDirty();
                }
            }
        } else if (intensity > 0.0F) {
            this.addOverlay(tex, mask, intensity, category);
        }
    }

    public float addBlood(String tex, BloodBodyPartType bodyPart, float intensity) {
        String string = "media/textures/BloodTextures/" + CharacterSmartTexture.MaskFiles[bodyPart.index()] + ".png";
        int _int = CharacterSmartTexture.DecalOverlayCategory + bodyPart.index();
        return this.addBlood(tex, string, intensity, _int);
    }

    public float addDirt(String tex, BloodBodyPartType bodyPart, float intensity) {
        String string = "media/textures/BloodTextures/" + CharacterSmartTexture.MaskFiles[bodyPart.index()] + ".png";
        int _int = CharacterSmartTexture.DirtOverlayCategory + bodyPart.index();
        return this.addDirt(tex, string, intensity, _int);
    }

    public float addBlood(String tex, String mask, float intensity, int category) {
        TextureCombinerCommand textureCombinerCommand = this.getFirstFromCategory(category);
        if (textureCombinerCommand == null) {
            this.addOverlay(tex, mask, intensity, category);
            return intensity;
        } else {
            for (int _int = 0; _int < textureCombinerCommand.shaderParams.size(); _int++) {
                TextureCombinerShaderParam textureCombinerShaderParam = (TextureCombinerShaderParam)textureCombinerCommand.shaderParams.get(_int);
                if (textureCombinerShaderParam.name.equals("intensity")) {
                    float _float = textureCombinerShaderParam.min;
                    _float += intensity;
                    _float = Math.min(1.0F, _float);
                    if (textureCombinerShaderParam.min != _float || textureCombinerShaderParam.max != _float) {
                        textureCombinerShaderParam.min = textureCombinerShaderParam.max = _float;
                        this.setDirty();
                    }

                    return _float;
                }
            }

            this.addOverlay(tex, mask, intensity, category);
            return intensity;
        }
    }

    public float addDirt(String tex, String mask, float intensity, int category) {
        TextureCombinerCommand textureCombinerCommand = this.getFirstFromCategory(category);
        if (textureCombinerCommand == null) {
            this.addDirtOverlay(tex, mask, intensity, category);
            return intensity;
        } else {
            for (int _int = 0; _int < textureCombinerCommand.shaderParams.size(); _int++) {
                TextureCombinerShaderParam textureCombinerShaderParam = (TextureCombinerShaderParam)textureCombinerCommand.shaderParams.get(_int);
                if (textureCombinerShaderParam.name.equals("intensity")) {
                    float _float = textureCombinerShaderParam.min;
                    _float += intensity;
                    _float = Math.min(1.0F, _float);
                    if (textureCombinerShaderParam.min != _float || textureCombinerShaderParam.max != _float) {
                        textureCombinerShaderParam.min = textureCombinerShaderParam.max = _float;
                        this.setDirty();
                    }

                    return _float;
                }
            }

            this.addOverlay(tex, mask, intensity, category);
            return intensity;
        }
    }

    public void removeBlood() {
        for (int _int = 0; _int < BloodBodyPartType.MAX.index(); _int++) {
            this.removeBlood(BloodBodyPartType.FromIndex(_int));
        }
    }

    public void removeDirt() {
        for (int _int = 0; _int < BloodBodyPartType.MAX.index(); _int++) {
            this.removeDirt(BloodBodyPartType.FromIndex(_int));
        }
    }

    public void removeBlood(BloodBodyPartType bodyPart) {
        TextureCombinerCommand textureCombinerCommand = this.getFirstFromCategory(CharacterSmartTexture.DecalOverlayCategory + bodyPart.index());
        if (textureCombinerCommand != null) {
            for (int _int = 0; _int < textureCombinerCommand.shaderParams.size(); _int++) {
                TextureCombinerShaderParam textureCombinerShaderParam = (TextureCombinerShaderParam)textureCombinerCommand.shaderParams.get(_int);
                if (textureCombinerShaderParam.name.equals("intensity") && (textureCombinerShaderParam.min != 0.0F || textureCombinerShaderParam.max != 0.0F)) {
                    textureCombinerShaderParam.min = textureCombinerShaderParam.max = 0.0F;
                    this.setDirty();
                }
            }
        }
    }

    public void removeDirt(BloodBodyPartType bodyPart) {
        TextureCombinerCommand textureCombinerCommand = this.getFirstFromCategory(CharacterSmartTexture.DirtOverlayCategory + bodyPart.index());
        if (textureCombinerCommand != null) {
            for (int _int = 0; _int < textureCombinerCommand.shaderParams.size(); _int++) {
                TextureCombinerShaderParam textureCombinerShaderParam = (TextureCombinerShaderParam)textureCombinerCommand.shaderParams.get(_int);
                if (textureCombinerShaderParam.name.equals("intensity") && (textureCombinerShaderParam.min != 0.0F || textureCombinerShaderParam.max != 0.0F)) {
                    textureCombinerShaderParam.min = textureCombinerShaderParam.max = 0.0F;
                    this.setDirty();
                }
            }
        }
    }

    public String getTexName() {
        return this.m_texName;
    }
}
